using Game.Main.Model;
using UnityEngine;

namespace Game.Component
{
	public class DragModelItem : BaseItem
	{
		private Sprite originalSprite;

		private Vector3 originalPosition;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
		}

		public override void TouchDown(TouchEventData touchEventData)
		{
			if (base.itemData.canDrag)
			{
				if (originalSprite == null)
				{
					originalSprite = model.GetComponent<SpriteRenderer>().sprite;
				}
				originalPosition = model.localPosition;
				Transform transform = model.Find("DragModel");
				if (transform != null)
				{
					model.GetComponent<SpriteRenderer>().sprite = transform.GetComponent<SpriteRenderer>().sprite;
					model.localPosition += transform.localPosition;
				}
			}
			base.TouchDown(touchEventData);
		}

		public override void TouchUp(TouchEventData touchEventData)
		{
			if (base.itemData.canDrag)
			{
				model.GetComponent<SpriteRenderer>().sprite = originalSprite;
				model.localPosition = originalPosition;
			}
			base.TouchUp(touchEventData);
		}
	}
}
